home *** CD-ROM | disk | FTP | other *** search
- /* XGStdGroupBox.cpp
- *
- * this is my internal implementation of a static text object.
- * This is something I simply roll myself
- */
-
- /* YAAF - Yet another application framework
- * Copyright (C) 1997 William Edward Woody and In Phase Consulting
- *
- * This library is free software; you can redistribute it
- * and/or modify it under the terms of the GNU Library
- * General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or any
- * later version.
- *
- * This library is distributed in the hope that it will be
- * useful, but WITHOUT ANY WARRANTY; without even the implied
- * warranty of MERCHANTABIILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU Library General Public License for
- * more details.
- *
- * You should have received a copy of the GNU Library General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * To contact the author, either e-mail me at
- * woody@alumni.caltech.edu, or write to us at
- *
- * William Edward Woody
- * In Phase Consulting
- * 1545 Ard Eevin Avenue
- * Glendale, CA 91202
- */
-
- #include <string.h>
- #include <XError.h>
- #include <XDataUtil.h>
- #include <XStdText.h>
- #include <XApplication.h>
- #include <XStdControls.h>
-
- /************************************************************************/
- /* */
- /* Construction/Destruction */
- /* */
- /************************************************************************/
-
- /* XGStdGroupBox::XGStdGroupBox
- *
- * Initialize me
- */
-
- XGStdGroupBox::XGStdGroupBox(XGView *v, XGArgStream &s) :
- XGStdText(v,s,true)
- {
- char buffer[256];
- s.GetString(sizeof(buffer),buffer);
- Init(buffer);
- }
-
- XGStdGroupBox::XGStdGroupBox(XGView *v, XGSTextInitRecord &s) :
- XGStdText(v,s.v,true)
- {
- Init(s.text);
- }
-
-
- /* XGStdGroupBox::~XGStdGroupBox
- *
- * Delete me
- */
-
- XGStdGroupBox::~XGStdGroupBox()
- {
- }
-
- /************************************************************************/
- /* */
- /* Text Drawing */
- /* */
- /************************************************************************/
-
- /* XGStdGroupBox::GetText
- *
- * Get the text contents of this
- */
-
- void XGStdGroupBox::GetText(char *text)
- {
- #if OPT_MACOS == 1
- strcpy(text,fString.Get());
- #endif
-
- #if OPT_WINOS == 1
- ::GetWindowText(_GetHWND(),text,256);
- #endif
- }
-
- /* XGStdGroupBox::SetText
- *
- * Set the text and force a redraw
- */
-
- void XGStdGroupBox::SetText(char *text)
- {
- #if OPT_MACOS == 1
- fString = text;
- #endif
-
- #if OPT_WINOS == 1
- ::SetWindowText(_GetHWND(),text);
- #endif
-
- InvalView();
- }
-
- /************************************************************************/
- /* */
- /* Static Control Drawing */
- /* */
- /************************************************************************/
-
- /* XGStdGroupBox::DoDrawView
- *
- * Draw this thing
- */
-
- void XGStdGroupBox::DoDrawView(Rect)
- {
- #if OPT_MACOS == 1
- XGDraw draw(this);
- Rect r;
- Rect s;
- unsigned char buffer[256];
- short i;
- FontInfo finfo;
-
- r = GetContentRect();
- cvtc2p(buffer,fString.Get());
- ::TextFont(fFont);
- ::TextSize(fSize); // request current font and size
- ::EraseRect(&r);
- ::GetFontInfo(&finfo);
-
- // Calculate the rectangle things go into
- s.left = r.left + 8;
- s.right = r.right - 8;
- i = s.left + ::StringWidth(buffer);
- if (s.right > i) s.right = i;
- s.top = r.top;
- s.bottom = s.top + finfo.ascent + finfo.descent;
- r.top += finfo.ascent - 3;
-
- // Draw the box
- ::MoveTo(s.left-3,r.top);
- ::LineTo(r.left,r.top);
- ::LineTo(r.left,r.bottom-1);
- ::LineTo(r.right-1,r.bottom-1);
- ::LineTo(r.right-1,r.top);
- ::LineTo(s.right+3,r.top);
-
- // Clip and draw the text
- r.right = s.right;
- r.top = s.top;
- draw.ClipRect(&r);
- ::MoveTo(s.left,s.top+finfo.ascent);
- ::DrawString(buffer);
- #endif
- }
-
- /************************************************************************/
- /* */
- /* Internal Initialization */
- /* */
- /************************************************************************/
-
- /* XGStdGroupBox::Init
- *
- * Initialization central
- */
-
- void XGStdGroupBox::Init(char *buffer)
- {
- long l;
-
- l = GetParent()->ReceiveDispatch(KEventGetFont,GetViewID(),(void *)&this);
- #if OPT_MACOS == 1
- fFont = GETHIWORD(l);
- fSize = GETLOWORD(l);
- fString = buffer;
- #endif
-
- #if OPT_WINOS == 1
- Rect r;
- HWND w;
-
- /*
- * Get the location of the control in the parent's coordinate
- * system
- */
-
- r = GetContentRect();
- if (GetParent()) {
- ViewToGlobal(&r);
- GetParent()->GlobalToView(&r);
- }
-
- /*
- * Create the control window
- */
-
- w = CreateWindow("BUTTON", // control class
- buffer, // control title
- WS_CHILD | BS_GROUPBOX, // control window flags
- r.left,
- r.top,
- r.right-r.left,
- r.bottom-r.top, // control location
- GetParent()->_GetHWND(), // container window
- NULL, // no menu
- _GInstance, // My app instance
- NULL); // no additional args
- if (w == NULL) {
- throw XPostError("Unable to make group box");
- }
-
- _SetHWND(w); // set me as the window
- SetProp(w,_GViewClass,(HANDLE)this);
- if (IsVisible()) ShowWindow(w,SW_SHOW);
- EnableWindow(w,IsEnabled()); // set me up
- #endif
- }
-
-